package com.ys.filelib.filedialog.view;

import android.content.Context;
import android.util.Log;

import com.ys.filelib.R;
import com.ys.filelib.filedialog.FileUtil;
import com.ys.filelib.filedialog.adapter.base.BaseViewHolder;
import com.ys.filelib.filedialog.loader.FileLoader;

public class AdapterUpdateView {

    public static void updateViewInfo(Context context, BaseViewHolder holder, String item) {
        int fileType = FileUtil.getFileType(item);
        Log.e("cdl", "==updateViewInfo=" + fileType);
        switch (fileType) {
            case FileUtil.FILE_AUDIO:
                holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_audio);
                break;
            case FileUtil.FILE_VIDEO:
                holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_video);
                break;
            case FileUtil.FILE_GIF:
            case FileUtil.FILE_IMAGE:
                FileLoader.with(context)
                    .load(item)
                    .override(200, 200)
                    .error(R.drawable.ic_doc_image)
                    .into(holder.getView(R.id.iv_image));
                break;
            case FileUtil.FILE_APK:
                holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_apk);
                break;
            case FileUtil.FILE_WORD:
                holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_word);
                break;
            case FileUtil.FILE_XLS:
                holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_excel);
                break;
            case FileUtil.FILE_PPT:
                holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_powerpoint);
                break;
            case FileUtil.FILE_PDF:
                holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_pdf);
                break;
            case FileUtil.FILE_WBD:
                holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_wbd);
                break;
            case FileUtil.FILE_OFFICE:
                if (FileUtil.isExcel(item)) {
                    holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_excel);
                } else if (FileUtil.isPPt(item)) {
                    holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_powerpoint);
                } else if (FileUtil.isPdf(item)) {
                    holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_pdf);
                } else if (FileUtil.isWord(item)) {
                    holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_word);
                } else {
                    holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_unknown);
                }
                break;
            case FileUtil.FILE_TEXT:
            case FileUtil.FILE_HTML:
            case FileUtil.FILE_XML:
                holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_txt);
                break;
            case FileUtil.FILE_COMPRESS:
                holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_archive);
                break;
            default:
                holder.setImageResource(R.id.iv_image, R.drawable.ic_doc_unknown);
                break;
        }
    }

}
